package com.kingyun.gpsinspection.purificationservice.services.som.innerservice.impl;

import com.kingyun.gpsinspection.purificationservice.dao.mapper.som.UserMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.Employee;
import com.kingyun.gpsinspection.purificationservice.facade.model.som.User;
import com.kingyun.gpsinspection.purificationservice.facade.service.som.SomUserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yangcs on 2017/1/9.
 */
public class SomUserServiceImpl implements SomUserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 用户登录
     * @param loginName     用户名
     * @param password      密码
     * @return
     */
    @Override
    public User login(String loginName, String password) {
        Map map = new HashMap();
        map.put("loginName",loginName);
        map.put("password",password);
        return userMapper.login(map);
    }

    /**
     * 验证用户token值
     * @param token
     * @return
     */
    @Override
    public String checkUser(String token) {
        return userMapper.checkUser(token);
    }

    /**
     * * 登录/注销成功后更新token值 以及记录日志
     * @param userId    用户ID
     * @param token     token值
     * @param type      1登录，0注销
     * @return
     */
    @Override
    public int updateToken(String userId, String token, int type) {
        Map map = new HashMap();
        map.put("userId",userId);
        map.put("token",token);
        int num = userMapper.updateToken(map);
        // TODO: 2017/1/9  记录登录注销日志
        return num;
    }

    /**
     * 验证用户名是否存在
     * @param loginName 用户名
     * @return
     */
    @Override
    public int checkLogin(String loginName) {
        return userMapper.checkLogin(loginName);
    }

    @Override
    public Employee getLoginEmployee() {
        Employee employee = new Employee();
        employee.setEmployeeId("22A257C49BD9498BB9AA981E19hxq");
        return employee;
    }

    /**
     * 根据组织机构id 查询 组织人员
     * @param userId
     * @return
     */
    @Override
    public List<User> getOrgUsers(String userId) {
        return userMapper.getOrgUsers(userId);
    }

    /**
     * 根据工卡id或者邮箱查询用户
     * @param cardId
     * @return
     */
    @Override
    public User queryByCardId(String cardId) {
        return userMapper.queryByCardId(cardId);
    }

    /**
     * 获取调度室的人员
     * @return
     */
    @Override
    public List<User> getDdsUsers() {
        return userMapper.getDdsUsers();
    }

    /**
     * 根据id查询用户
     * @param userId
     * @return
     */
    @Override
    public User queryByUserId(String userId) {
        return userMapper.queryByUserId(userId);
    }

    /**
     * 快捷登录
     * @param userId
     * @return
     */
    @Override
    public User loginByUserId(String userId) {
        return userMapper.loginByUserId(userId);
    }

    /**
     * 根据ID集合查询名字
     * @param list
     * @return
     */
    @Override
    public String queryUserNamesByIds(List<String> list) {
        return userMapper.queryUserNamesByIds(list);
    }
}
